home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / AsyncBlitter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  5.2 KB  |  200 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef f_ASYNCBLITTER_H
  19. #define f_ASYNCBLITTER_H
  20.  
  21. #include <windows.h>
  22. #include <vfw.h>
  23. #include <ddraw.h>
  24.  
  25. class IDDrawSurface;
  26.  
  27. class AsyncBlitRequestDrawDib {
  28. public:
  29.     HDRAWDIB hdd;
  30.     HDC        hdc;
  31.     int        xDst, yDst;
  32.     int        dxDst, dyDst;
  33.     LPBITMAPINFOHEADER lpbi;
  34.     LPVOID    lpBits;
  35.     int        xSrc;
  36.     int        ySrc;
  37.     int        dxSrc;
  38.     int        dySrc;
  39.     UINT    wFlags;
  40. };
  41.  
  42. class AsyncBlitRequestStretchBlt {
  43. public:
  44.     HDC        hdcDst;
  45.     int        xDst, yDst;
  46.     int        dxDst, dyDst;
  47.     HDC        hdcSrc;
  48.     int        xSrc, ySrc;
  49.     int        dxSrc, dySrc;
  50. };
  51.  
  52. class AsyncBlitRequestStretchDIBits {
  53. public:
  54.     HDC        hdc;
  55.     int        xDst, yDst, dxDst, dyDst;
  56.     int        xSrc, ySrc, dxSrc, dySrc;
  57.     const void    *pBits;
  58.     const BITMAPINFO *pBitsInfo;
  59.     UINT    iUsage;
  60.     DWORD    dwRop;
  61. };
  62.  
  63. class AsyncBlitRequestDirectDrawCopy {
  64. public:
  65.     void    *data;
  66.     BITMAPINFOHEADER *pbih;
  67.     IDDrawSurface *pDest;
  68.     bool    bFirst;
  69.     bool    bFieldBDominant;
  70. };
  71.  
  72. class AsyncBlitRequestDirectDrawBlit {
  73. public:
  74.     IDDrawSurface *pSrc;
  75.     IDirectDrawSurface *pDest;
  76.     RECT r;
  77.     bool bFieldBDominant;
  78.     bool bFirst;
  79. };
  80.  
  81. class AsyncBlitRequestICDraw {
  82. public:
  83.     HIC hic;
  84.     DWORD dwFlags;
  85.     LPVOID pFormat;
  86.     LPVOID pData;
  87.     DWORD cbData;
  88.     LONG lTime;
  89. };
  90.  
  91. class AsyncBlitRequestAFC {
  92. public:
  93.     void (*pFunc)(void *);
  94.     void *pData;
  95. };
  96.  
  97. class AsyncBlitRequest {
  98. public:
  99.     enum {
  100.         REQTYPE_DRAWDIB,
  101.         REQTYPE_STRETCHBLT,
  102.         REQTYPE_DIRECTDRAWCOPY,
  103.         REQTYPE_DIRECTDRAWBLIT,
  104.         REQTYPE_ICDRAW,
  105.         REQTYPE_STRETCHDIBITS,
  106.         REQTYPE_AFC,
  107.         REQTYPE_BITBLTLACED,
  108.         REQTYPE_DIRECTDRAWCOPYLACED,
  109.         REQTYPE_DIRECTDRAWBLITLACED,
  110.     } type;
  111.     DWORD    bufferID;
  112.     DWORD    framenum;
  113.  
  114.     union {
  115.         AsyncBlitRequestDrawDib    drawdib;
  116.         AsyncBlitRequestStretchBlt stretchblt;
  117.         AsyncBlitRequestDirectDrawCopy    ddcopy;
  118.         AsyncBlitRequestDirectDrawBlit    ddblit;
  119.         AsyncBlitRequestICDraw    icdraw;
  120.         AsyncBlitRequestStretchDIBits stretchdibits;
  121.         AsyncBlitRequestAFC afc;
  122.     };
  123. };
  124.  
  125. class AsyncBlitter {
  126. private:
  127.     AsyncBlitRequest *requests;
  128.     int max_requests;
  129.  
  130.     volatile HANDLE    hThreadDraw;
  131.     HANDLE            hEventDraw;
  132.     HANDLE            hEventDrawReturn;
  133.     HANDLE            hEventAbort;
  134.     volatile DWORD    dwLockedBuffers;
  135.     DWORD            dwPulseFrame;
  136.     DWORD            dwDrawFrame;
  137.     volatile BOOL    fAbort;
  138.     BOOL            fPulsed;
  139.     volatile bool    fFlush;
  140.  
  141.     int        (*pulseCallback)(void *, DWORD);
  142.     void    *pulseCallbackData;
  143.  
  144.     void release(DWORD);
  145.     BOOL waitPulse(DWORD);
  146.     static void drawThread(void *);
  147.     bool DoRequest(AsyncBlitRequest *req);
  148.     void drawThread2();
  149.     HRGN CreateLacedRegion(int w, int h, int yo);
  150.  
  151. public:
  152.     AsyncBlitter();
  153.     AsyncBlitter(int max_requests);
  154.     ~AsyncBlitter();
  155.  
  156.     enum {
  157.         PCR_OKAY,
  158.         PCR_NOBLIT,
  159.         PCR_WAIT,
  160.     };
  161.  
  162. #ifdef _DEBUG
  163.     enum {
  164.         LOCK_NONE        = 0,
  165.         LOCK_DESTROY    = 0x00000001L,
  166.         LOCK_LOCK        = 0x00000002L,
  167.         LOCK_PULSE        = 0x00000004L,
  168.         LOCK_POST        = 0x00000008L,
  169.         LOCK_ASYNC_EXIT    = 0x00000010L,
  170.     };
  171.     
  172.     volatile long lock_state;
  173. #endif
  174.  
  175.     void enablePulsing(BOOL);
  176.     void setPulseCallback(int (*pc)(void *, DWORD), void *pcd);
  177.     void pulse();
  178.     void setPulseClock(DWORD clk);
  179.     void lock(DWORD);
  180.     void unlock(DWORD);
  181.     void nextFrame(long adv=1);
  182.     long getFrameDelta();
  183.     void post(DWORD, HDRAWDIB, HDC, int, int, int, int, LPBITMAPINFOHEADER, LPVOID, int, int, int, int, UINT);
  184.     void postBitBltLaced(DWORD id, HDC hdcDest, int xDst, int yDst, int dxDst, int dyDst, HDC hdcSrc, int xSrc, int ySrc, bool bFieldBDominant);
  185.     void postStretchBlt(DWORD id, HDC hdcDest, int xDst, int yDst, int dxDst, int dyDst, HDC hdcSrc, int xSrc, int ySrc, int dxSrc, int dySrc);
  186.     void postStretchDIBits(DWORD id, HDC hdc, int xDst, int yDst, int dxDst, int dyDst, int xSrc, int ySrc, int dxSrc, int dySrc, const void *pBits, const BITMAPINFO *pBitsInfo, UINT iUsage, DWORD dwRop);
  187.     void postDirectDrawCopy(DWORD id, void *data, BITMAPINFOHEADER *pbih, IDDrawSurface *pDest);
  188.     void postDirectDrawCopyLaced(DWORD id, void *data, BITMAPINFOHEADER *pbih, IDDrawSurface *pDest, bool bFieldBDominant);
  189.     void postDirectDrawBlit(DWORD id, IDirectDrawSurface *pDst, IDDrawSurface *pSrc, int xDst, int yDst, int dxDst, int dyDst);
  190.     void postDirectDrawBlitLaced(DWORD id, IDirectDrawSurface *pDst, IDDrawSurface *pSrc, int xDst, int yDst, int dxDst, int dyDst, bool bFieldBDominant);
  191.     void postICDraw(DWORD id, HIC hic, DWORD dwFlags, LPVOID pFormat, LPVOID pData, DWORD cbData, LONG lTime);
  192.     void postAFC(DWORD id, void (*pFunc)(void *), void *pData);
  193.     void abort();
  194.     void flush();
  195.  
  196.     bool ServiceRequests(bool fWait);
  197. };
  198.  
  199. #endif
  200.